package com.fanfutian.eventproject.mapper;

import com.fanfutian.eventproject.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


@Mapper
public interface UserMapper {


    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from db_event_project.user where username=#{username}")
    User findUserByUsername(String username);


    /**
     * 注册用户信息
     * @param username
     * @param md5DigestAsHexPassword
     */
    @Insert("insert into db_event_project.user(username, password, create_time, update_time) " +
            "values (#{username}, #{md5DigestAsHexPassword}, now(),now())")
    void addUser(String username, String md5DigestAsHexPassword);


    /**
     * 更新用户信息
     * @param user
     */
    @Update("update db_event_project.user set nickname=#{nickname}, email=#{email}, update_time=#{updateTime} where id=#{id}")
    void updateUserInfo(User user);


    /**
     * 更新用户头像
     * @param avatarUrl
     * @param userId
     */
    @Update("update db_event_project.user set user_pic=#{avatarUrl}, update_time=now() where id=#{userId}")
    void updateUserAvatar(String avatarUrl, Integer userId);


    /**
     * 更新用户密码
     * @param newPwd
     * @param id
     */
    @Update("update db_event_project.user set password=#{newPwd}, update_time=now() where id=#{id}")
    void updateUserPwd(String newPwd, Integer id);
}
